package corsi.hibernate.demo.web.transazioni.servlet;

import java.io.IOException;
import java.util.List;
import java.util.Vector;
import java.util.logging.Logger;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import corsi.hibernate.demo.web.transazioni.domain.AbstractValueObject;
import corsi.hibernate.demo.web.transazioni.domain.CD;
import corsi.hibernate.demo.web.transazioni.services.exceptions.ServiceException;
import corsi.hibernate.demo.web.transazioni.services.impl.DemoTransazioniEEServiceImpl;

/**
 * Servlet implementation class ServletDemoTransazioniJTA
 */
public class ServletDemoTransazioniJTA extends HttpServlet {
	private static final long serialVersionUID = 1L;
	static Logger logger =Logger.getLogger("ServletDemoTransazioniJTA");
      
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ServletDemoTransazioniJTA() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		try {
			DemoTransazioniEEServiceImpl servizioTransazioni = new DemoTransazioniEEServiceImpl();
			CD cd1 = servizioTransazioni.findCDByID(1L);
			logger.info("CD trovato "+cd1.toString());
			
			
			List<AbstractValueObject> trovati = new Vector ();
			trovati.add(servizioTransazioni.findCDByID(3L));
			trovati.add(servizioTransazioni.findCDByID(7L));
			trovati.add(servizioTransazioni.findCDByID(9L));
			trovati.add(servizioTransazioni.findCDByID(11L));
			
			servizioTransazioni.aggiornaCatalogo(trovati);
			/*
			RequestDispatcher dispatcher = request.getRequestDispatcher("/output.jsp");
			request.setAttribute("Cd", arg1)
			*/
		} catch (ServiceException ecc) {

		}
	
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
